package com.tan.lbs.activity;

import com.tan.lbs.activity.R;
import com.tan.lbs.activity.MainActivity.MainCoverClickListener;
import com.tan.lbs.dao.GameDAO;
import com.tan.lbs.dao.impl.GameDAOImpl;
import com.tan.lbs.entity.Game;
import com.tan.lbs.util.Constants;
import com.tan.lbs.util.ResourceReader;
import com.tan.lbs.util.URLs;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class GameInfoTabActivity extends Activity{
	
	private Game game;
	private String gameID;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.gameinfotab);
		gameID  = getSharedPreferences(Constants.PREFS_NAME, 0).getString("currentGameID", "");
		GameDAO gameDAO = new GameDAOImpl(this);
		game  = gameDAO.readGameDetail(gameID);
		((TextView) findViewById(R.id.gamepublishtitle)).setText(game.getPublishTitle());
		
		Bitmap icon = ResourceReader.readImage(this,
				URLs.gameResourceLoc + gameID + "/"
						+ game.getIconID());

		ImageView gameIcon = (ImageView)findViewById(R.id.gameInfoIcon);
		gameIcon.setImageBitmap(icon);
		
		Bitmap cover = ResourceReader.readImage(this,
				URLs.gameResourceLoc + gameID + "/"
						+ game.getGameCoverID());

		ImageView gameCover = (ImageView)findViewById(R.id.gameCover);
		gameCover.setImageBitmap(cover);
		
		((TextView) findViewById(R.id.gamepublishdescription)).setText(game.getPublishDescription());
		((TextView) findViewById(R.id.authorText)).setText(game.getAuthor());
		((TextView) findViewById(R.id.emailText)).setText(game.getEmail());
		((TextView) findViewById(R.id.orgText)).setText(game.getPublishAgent());
		((Button) findViewById(R.id.introBtn)).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent();
				intent.putExtra("intro", game.getIntroduction());
				intent.setClass(GameInfoTabActivity.this, GameIntroActivity.class);
				GameInfoTabActivity.this.startActivity(intent);
			}
		});
		
		this.setTitle(game.getPublishTitle());
		this.setTitleColor(Color.GRAY);
	}
}
